import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import NProgress from 'nprogress';
import "nprogress/nprogress.css";
import Layout from '../layout/index.vue'
const routes: Array<RouteRecordRaw> = [
    {
        path: '/login',
        component: () => import('../views/login.vue'),
        meta: {
            hidden: true,
        }
    },
    {
        path: '/lowCode',
        component: () => import('../views/lowCode/index.vue'),
        meta: {
            hidden: true,
        }
    },
    {
        path: '/',
        redirect: '/index',
        component: Layout,
        name: "Index",
        meta: {
            title: "首页",
            icon: 'house',
        },
        children: [
            {
                path: "index",
                name: "Index",
                component: () => import("../views/index.vue"),
                meta: {
                    title: "首页",
                    icon: 'house'
                }
            }
        ]
    },
    {
        path: '/user',
        redirect: '/index',
        component: Layout,
        meta: {
            title: "用户管理",
            icon: 'User'
        },
        children: [
            {
                path: "user",
                name: "User",
                component: () => import("../views/user/User.vue"),
                meta: {
                    title: "用户管理",
                    
                }
            },
            {
                path: "role",
                name: "Role",
                component: () => import("../views/user/Role.vue"),
                meta: {
                    title: "角色管理",
                    icon: 'Role'
                }
            },
            {
                path: "mine",
                name: "Mine",
                component: () => import("../views/user/Mine.vue"),
                meta: {
                    title: "个人中心",
                    icon: 'Role'
                }
            },
            {
                path: "setpwd",
                name: "SetPwd",
                component: () => import("../views/user/SetPwd.vue"),
                meta: {
                    title: "密码管理",
                    icon: 'Role'
                }
            }
        ]
    },
    {
        path: '/model',
        redirect: '/index',
        component: Layout,
        meta: {
            title: "动画组件123",
            icon: 'star'
        },
        children: [
            {
                path: "todoList",
                name: "TodoList",
                component: () => import("../views/todoList/index.vue"),
                meta: {
                    title: "备忘录",
                    icon: 'SwitchButton'
                }
            },

        ]
    },
    {
        path: '/animation',
        redirect: '/index',
        component: Layout,
        meta: {
            title: "动画组件",
            icon: 'star'
        },
        children: [
            {
                path: "button",
                name: "Button",
                component: () => import("../views/animition/button.vue"),
                meta: {
                    title: "按钮",
                    icon: 'SwitchButton'
                }
            },
            {
                path: "text",
                name: "Text",
                component: () => import("../views/animition/text.vue"),
                meta: {
                    title: "文本",
                    icon: 'NoteBook'
                }
            }
        ]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes: routes
})

router.beforeEach((to, from, next) => {
    NProgress.start();
    next()
})

router.afterEach((to, from) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    }
    NProgress.done();
})


export default router